﻿using System;
using System.Runtime.InteropServices;

namespace NetToolsV2
{
    internal static class NativeMethods
    {
        #region Memory Management
        [DllImport("coredll")]
        internal static extern IntPtr LocalAlloc(int flags, int size);
        [DllImport("coredll")]
        internal static extern IntPtr LocalFree(IntPtr pMem);

        public const int LMEM_ZEROINIT = 0x40;

        #endregion

        #region IPHLPAPI P/Invokes
        [DllImport("iphlpapi", SetLastError = true)]
        internal static extern IntPtr IcmpCreateFile();

        [DllImport("iphlpapi", SetLastError = true)]
        [return: MarshalAs(UnmanagedType.Bool)]
        internal static extern bool IcmpCloseHandle(IntPtr h);

        [DllImport("iphlpapi", SetLastError = true)]
        internal static extern uint IcmpSendEcho(
                         IntPtr IcmpHandle,
                         uint DestinationAddress,
                         byte[] RequestData,
                         short RequestSize,
                         byte[] RequestOptions,
                         byte[] ReplyBuffer,
                         int ReplySize,
                         int Timeout);

        #endregion
    }
}
